package com.wolfking.jeesite.util;

import org.apache.commons.lang3.StringUtils;

import java.util.function.Supplier;

public class DefUtils {
    public static <T> T nullDef(T obj, T defaults) {
        if (obj == null) {
            return defaults;
        } else if (obj instanceof String) {
            if (StringUtils.isBlank(((String) obj))) {
                return defaults;
            } else {
                return obj;
            }
        } else {
            return obj;
        }
    }

    public static <T> T condition(Supplier<Boolean> supplier, T a, T b) {
        return supplier.get() ? a : b;
    }
}
